"""
定义一个狗类,里面有一个列表成员变量(列表的元素是字典), 分别记录了 3种颜色的狗的颜色, 数量,和价格;
实现狗的买卖交易方法; 打印输出经过2-3次买卖方法后,剩下的各类狗的数量;
"""
class Dog(object):
    def __init__(self):
        self.attr = [
            {'color':'red', 'amount':10, 'price': 500},
            {'color':'green', 'amount':20, 'price': 1000},
            {'color':'blue','amount':30,'price':2000}
        ]


    def buy_red(self, num):
        self.attr[0]['amount'] += num

    def buy_green(self, num):
        self.attr[1]['amount'] += num

    def buy_blue(self, num):
        self.attr[2]['amount'] += num

    def sell_red(self, num):
        self.attr[0]['amount'] -= num

    def sell_green(self, num):
        self.attr[1]['amount'] += num

    def sell_blue(self, num):
        self.attr[2]['amount'] += num


d = Dog()
print(d.attr)
d.buy_red(5)
print(d.attr)
d.sell_green(1)
d.buy_blue(60)
print(d.attr)